﻿using System;
using MagistrAPI.MathModel;
using NUnit.Framework;

namespace TestMagistrAPI
{
    [TestFixture]
    class MathModelFuncTextFixture
    {
        [SetUp]
        public void Init()
        {
            
        }

        [Test]
        public void TestHMethod()
        {
            var h = MathModelFunc.H(3, 5, 12);
            Assert.AreEqual(Math.Round(-6360848.2920709308, 0), Math.Round(h, 0));
        }

        [Test]
        public void TestrrMethod()
        {
            var rr = MathModelFunc.Rr(3, 5, 12);
            Assert.AreEqual(Math.Round(13.3416640641, 5), Math.Round(rr, 5));
        }

        [Test]
        public void TestRMethod()
        {
            var r = MathModelFunc.R(1.1184819711);
            Assert.AreEqual(Math.Round(6360861.6337353792, 0), Math.Round(r, 0));
        }

        [Test]
        public void TestPhiuuMethod()
        {
            var phiuu = MathModelFunc.Phiuu(3, 5, 12);
            Assert.AreEqual(Math.Round(1.1184819711, 5), Math.Round(phiuu, 5));
        }

        [Test]
        public void TestMrotvMethod()
        {
            double[,] matr = { { 25000, 0, 0 }, { 0, 441666.6666666667, 0 }, { 0, 0, 441666.6666666667 } };
            double e = 10e-15;
            double[,] rezult = MathModelFunc.Mrotv(matr, e);
            double[,] expectedRezult = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
            Assert.AreEqual(expectedRezult, rezult);
        }

        [Test]
        public void TestMatrTMethod()
        {
            double[,] matr = { { 2, 5 }, { 3, 7 } };
            double[,] expectedRezult = { { 2, 3 }, { 5, 7 } };
            Assert.AreEqual(expectedRezult, MathModelFunc.MatrT(matr, 2, 2));
        }

        [Test]
        public void TestMatrToMatrMethod()
        {
            double[,] firstMatr = { { 2, 5 }, { 3, 7 } };
            double[,] secondMatr = { { 2, 2, 1 }, { 1, 2, 1 } };
            double[,] expectedRezult = { { 9, 14, 7 }, { 13, 20, 10 } };
            Assert.AreEqual(expectedRezult, MathModelFunc.MatrToMatr(firstMatr, secondMatr, 2, 2, 3));
        }

        [Test]
        public void TestLsbUyMethod()
        {
            double[,] rezult = MathModelFunc.LsbUy(0.2, 0.4, 0.5, 0.2, 0.3, 0.1, 1.2, 0.3, 6.1);
            double[,] expectedRezult = new[,] {{0.2, 0.4, 0.5}, {0.2, 0.3, 0.1}, {1.2, 0.3, 6.1}};
            Assert.AreEqual(expectedRezult, rezult);
        }

        [Test]
        public void TestRxMethod()
        {
            double[] rezult = MathModelFunc.Rxyz(2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
            Assert.AreEqual(Math.Round(-3.7090805311e24/10e24, 5), Math.Round(rezult[0]/10e24, 5));
        }

        [Test]
        public void TestRyMethod()
        {
            double[] rezult = MathModelFunc.Rxyz(2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
            Assert.AreEqual(Math.Round(-3.7090805311e24 / 10e24, 5), Math.Round(rezult[1] / 10e24, 5));
        }

        [Test]
        public void TestRzMethod()
        {
            double[] rezult = MathModelFunc.Rxyz(2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
            Assert.AreEqual(Math.Round(-3.7090805311e24 / 10e24, 5), Math.Round(rezult[2] / 10e24, 5));
        }

        [Test]
        public void TestQMethod()
        {
            double rezult = MathModelFunc.Q(234, 3.2);
            Assert.AreEqual(Math.Round(33529.4548330667, 5), Math.Round(rezult, 5));
        }

        [Test]
        public void TestPhMethod()
        {
            double rezult = MathModelFunc.Ph(3456.0);
            Assert.AreEqual(Math.Round(0.8674898277, 5), Math.Round(rezult, 5));
        }

        [Test]
        public void TestLnpMethod()
        {
            double rezult = MathModelFunc.Lnp(25438.0);
            Assert.AreEqual(Math.Round(7.7660756868, 5), Math.Round(rezult, 5));
        }

        [Test]
        public void TestTmMethod()
        {
            double rezult = MathModelFunc.Tm(22222.0);
            Assert.AreEqual(Math.Round(216.66, 5), Math.Round(rezult, 5));
        }

        [Test]
        public void TestFMethod()
        {
            double rezult = MathModelFunc.F(63298.0);
            Assert.AreEqual(Math.Round(62675.3021194628, 5), Math.Round(rezult, 5));
        }

        [Test]
        public void TestVbuMethod()
        {
            double[] rezult = MathModelFunc.Vbu(236.0,764.0,567.0,123.0,345.0,34.0);
            Assert.AreEqual(Math.Round(344.9828375957, 5), Math.Round(rezult[1], 5));
        }

        [Test]
        public void TestVectMethod()
        {
            double[] rezult = MathModelFunc.Vect(3.0,4.0,2.0,7.0,8.0,9.0);
            Assert.AreEqual(-13, rezult[1]);
        }

        [Test]
        public void TestCxMethod()
        {
            double rezult = MathModelFunc.Cx(235.0, 65.0, 12.0, 123.0, 678.0, 89.0, 0.1, 0.2, 0.4, 0.5, 2.0, 0.5, 0.9, 0.1, 2.0);
            Assert.AreEqual(Math.Round(-0.2763237736, 5), Math.Round(rezult, 5));
        }

        [Test]
        public void TestααnbMethod()
        {
            double rezult = MathModelFunc.ααnb(235.0, 65.0, 12.0, 123.0, 678.0, 89.0, 0.1, 0.2, 0.4, 0.5, 2.0, 0.5, 0.9, 0.1, 2.0);
            Assert.AreEqual(Math.Round(1.2908294932, 5), Math.Round(rezult, 5));
        }

        [Test]
        public void TestVbsbyMethod()
        {
            double [] rezult = MathModelFunc.Vbsby(235.0, 65.0, 12.0, 123.0, 678.0, 89.0, 0.1, 0.2, 0.4, 0.5, 2.0, 0.5, 0.9, 0.1, 2.0);
            Assert.AreEqual(Math.Round(1389.4667660222, 5), Math.Round(rezult[1], 5));
        }

        [Test]
        public void TestLuysbMethod()
        {
            double[,] rezult = MathModelFunc.Luysb(2.0, 4.0, 2.0, 6.0, 5.0, 7.0, 3.0, 4.0, 8.0);
            var expectedRezult = new double[,] {{2, 6, 3}, {4, 5, 4}, {2, 7, 8}};
            Assert.AreEqual(expectedRezult, rezult);
        }

        [Test]
        public void TestCynMethod()
        {
            double rezult = MathModelFunc.Cyn(2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
            Assert.AreEqual(Math.Round(0.8164965809, 5), Math.Round(rezult, 5));
        }

        [Test]
        public void TestCyMethod()
        {
            double rezult = MathModelFunc.Cy(2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
            Assert.AreEqual(Math.Round(-0.5773502692, 5), Math.Round(rezult, 5));
        }

        [Test]
        public void TestCzMethod()
        {
            double rezult = MathModelFunc.Cz(2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
            Assert.AreEqual(Math.Round(-0.5773502692, 5), Math.Round(rezult, 5));
        }

        [Test]
        public void TestGuuMethod()
        {
            double []rezult = MathModelFunc.Guu(3,5,6);
            Assert.AreEqual(Math.Round(7.0868216744e30/10e30, 5), Math.Round(rezult[1]/10e30, 5));
        }

        [Test]
        public void TestφuuMethod()
        {
            double rezult = MathModelFunc.φuu(2.0, 3.0, 4.0);
            Assert.AreEqual(Math.Round(0.8372150032, 5), Math.Round(rezult, 5));
        }

        [Test]
        public void TestArcsinMethod()
        {
            double rezult = MathModelFunc.Arcsin(0.2,3.0);
            Assert.AreEqual(Math.Round(0.2013579208, 5), Math.Round(rezult, 5));
        }

        [Test]
        public void TestλλuMethod()
        {
            double rezult = MathModelFunc.λλu(2.0, 3.0, 4.0);
            Assert.AreEqual(Math.Round(0.9827937232, 5), Math.Round(rezult, 5));
        }

        [Test]
        public void TestGrMethod()
        {
            double rezult = MathModelFunc.Gr(2.0, 3.0, 4.0);
            Assert.AreEqual(Math.Round(1.1495199515e32 / 10e32, 5), Math.Round(rezult / 10e32, 5));
        }

        [Test]
        public void TestGφMethod()
        {
            double rezult = MathModelFunc.Gφ(2.0, 3.0, 4.0);
            Assert.AreEqual(Math.Round(6.8028775129e31 / 10e31, 5), Math.Round(rezult / 10e31, 5));
        }

        [Test]
        public void TestGλMethod()
        {
            double rezult = MathModelFunc.Gλ(2.0, 3.0, 4.0);
            Assert.AreEqual(0, rezult);
        }

        [Test]
        public void TestAbsVMethod()
        {
            double rezult = MathModelFunc.AbsV(2.0, 2.0, 1.0);
            Assert.AreEqual(3.0, rezult);
        }

        [Test]
        public void TestMxMethod()
        {
            double rezult = MathModelFunc.Mx(2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
            Assert.AreEqual(0, rezult);
        }

        [Test]
        public void TestMyMethod()
        {
            double rezult = MathModelFunc.My(2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
            Assert.AreEqual(Math.Round(-3.7090805311e24/10e24, 5), Math.Round(rezult/10e24, 5));
        }

        [Test]
        public void TestMzMethod()
        {
            double rezult = MathModelFunc.Mz(2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
            Assert.AreEqual(Math.Round(3.7090805311e24 / 10e24, 5), Math.Round(rezult / 10e24, 5));
        }

        [Test]
        public void TestMznMethod()
        {
            double rezult = MathModelFunc.Mzn(2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
            Assert.AreEqual(Math.Round(-0.0816496581, 5), Math.Round(rezult, 5));
        }

        [Test]
        public void TestLsbTrMethod()
        {
            double[,] rezult = MathModelFunc.LsbTr(2.0, 3.0, 4.0);
            Assert.AreEqual(Math.Round(0.4188689948, 5), Math.Round(rezult[1, 1], 5));
        }

        [Test]
        public void TestLtruMethod()
        {
            double[,] rezult = MathModelFunc.Ltru(2.0, 3.0, 4.0, 3.0, 2.0, 1.0);
            Assert.AreEqual(Math.Round(-0.7669539193, 5), Math.Round(rezult[2, 2], 5));
            Assert.AreEqual(Math.Round(-0.1588375688, 5), Math.Round(rezult[0, 2], 5));
        }

        [Test]
        public void TestLugL0Method()
        {
            double[,] rezult = MathModelFunc.LugL0(2.0, 3.0, 4.0, 3.0, 2.0, 1.0, 2.0, 7.0, 8.0);
            Assert.AreEqual(Math.Round(0.3350018798, 5), Math.Round(rezult[2, 2], 5));
            Assert.AreEqual(Math.Round(0.4462075554, 5), Math.Round(rezult[0, 0], 5));
            Assert.AreEqual(Math.Round(0.3598001453, 5), Math.Round(rezult[1, 1], 5));
            Assert.AreEqual(Math.Round(0.9108042576, 5), Math.Round(rezult[1, 2], 5));
            Assert.AreEqual(Math.Round(-0.3575673122, 5), Math.Round(rezult[2, 1], 5));
        }
    }
}
